home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Dialog Boxes / DrawOrFillEllipseWithApply / DrawOrFillEllipseWithApply.cs < prev    next >
Encoding:
Text File  |  2001-01-15  |  2.1 KB  |  65 lines

  1. //---------------------------------------------------------
  2. // DrawOrFillEllipseWithApply.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class DrawOrFillEllipseWithApply: Form
  9. {
  10.      Color colorEllipse = Color.Red;
  11.      bool  bFillEllipse = false;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new DrawOrFillEllipseWithApply());
  16.      }
  17.      public DrawOrFillEllipseWithApply()
  18.      {
  19.           Text = "Draw or Fill Ellipse with Apply";
  20.           ResizeRedraw = true;
  21.  
  22.           Menu = new MainMenu();
  23.           Menu.MenuItems.Add("&Options");
  24.           Menu.MenuItems[0].MenuItems.Add("&Color...", 
  25.                                    new EventHandler(MenuColorOnClick));
  26.      }
  27.      void MenuColorOnClick(object obj, EventArgs ea)
  28.      {
  29.           ColorFillDialogBoxWithApply dlg = 
  30.                                    new ColorFillDialogBoxWithApply();
  31.  
  32.           dlg.ShowApply = true;
  33.           dlg.Apply    += new EventHandler(ColorFillDialogOnApply);
  34.  
  35.           dlg.Color = colorEllipse;
  36.           dlg.Fill  = bFillEllipse;
  37.  
  38.           if (dlg.ShowDialog() == DialogResult.OK)
  39.           {
  40.                colorEllipse = dlg.Color;
  41.                bFillEllipse = dlg.Fill;
  42.                Invalidate();
  43.           }
  44.      }
  45.      void ColorFillDialogOnApply(object obj, EventArgs ea)
  46.      {
  47.           ColorFillDialogBoxWithApply dlg = 
  48.                                    (ColorFillDialogBoxWithApply) obj;
  49.  
  50.           colorEllipse = dlg.Color;
  51.           bFillEllipse = dlg.Fill;
  52.           Invalidate();
  53.      }
  54.      protected override void OnPaint(PaintEventArgs pea)
  55.      {
  56.           Graphics  grfx = pea.Graphics;
  57.           Rectangle rect = new Rectangle(0, 0, ClientSize.Width - 1,
  58.                                                ClientSize.Height - 1);
  59.           if(bFillEllipse)
  60.                grfx.FillEllipse(new SolidBrush(colorEllipse), rect);
  61.           else
  62.                grfx.DrawEllipse(new Pen(colorEllipse), rect);
  63.      }
  64. }
  65.